package com.ztmmm.module.exam.mapper;

import com.ztmmm.module.exam.entity.Exam;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 课程 Mapper 接口
 * </p>
 *
 * @author ztm
 * @since 2023-03-23
 */
@Mapper
public interface ExamMapper extends BaseMapper<Exam> {

    @Select("select el_exam.* from el_exam\n"+
            "where el_exam.open_type = 1\n"+
            "\n"+
            "union \n"+
            "\n"+
            "select el_exam.* from el_exam left join el_exam_depart on el_exam.id = el_exam_depart.exam_id\n"+
            "where el_exam_depart.depart_id in (select dept_id from sys_user where user_id = #{userId})\n"+
            "\n"+
            "union \n"+
            "\n"+
            "select el_exam.* from el_exam left join el_exam_user on el_exam.id = el_exam_user.exam_id\n"+
            "where el_exam_user.user_id = #{userId}")
    public List<Exam> findMyExam(String userId);
}
